package com.lagou.utils.executor;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 自定义线程池
 */
public class ExecutorPool {

    // 核心线程数
    private static final int CORE_POOL_SIZE = Math.max(Runtime.getRuntime().availableProcessors(), 4);
    private static final int MAX_MUN_POOL_SIZE = CORE_POOL_SIZE << 1;
    private static final int ALIVE_TIME = 4;

    private static final BlockingQueue<Runnable> WORK_QUEUE = new LinkedBlockingQueue<>(4);

    public static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE_POOL_SIZE,
            MAX_MUN_POOL_SIZE, ALIVE_TIME, TimeUnit.SECONDS, WORK_QUEUE);
}
